
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.6.1-1.12.2 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4.3.html" />
    
    
    <link rel="prev" href="4.1.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" >
            
                <a target="_blank" href="https://github.com/xfl03/CoreModTutor">
            
                    
                    源代码仓库（求star）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    目录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="0.html">
            
                <a href="0.html">
            
                    
                    0 绪论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    1 简介
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="1.1.html">
            
                <a href="1.1.html">
            
                    
                    CoreMod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="1.2.html">
            
                <a href="1.2.html">
            
                    
                    Java虚拟机
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="1.3.html">
            
                <a href="1.3.html">
            
                    
                    Minecraft混淆方式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    2 Java虚拟机
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" >
            
                <span>
            
                    
                    ClassLoader类加载器
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" >
            
                <span>
            
                    
                    ByteCode字节码
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" >
            
                <span>
            
                    
                    ASM
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    3 原版 CoreMod
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="3.1.html">
            
                <a href="3.1.html">
            
                    
                    直接修改class文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="3.2.html">
            
                <a href="3.2.html">
            
                    
                    JavaAgent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="3.3.html">
            
                <a href="3.3.html">
            
                    
                    LaunchWrapper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="3.4.html">
            
                <a href="3.4.html">
            
                    
                    ModLauncher
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    4 FML CoreMod
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="4.1.html">
            
                <a href="4.1.html">
            
                    
                    1.3.2-1.5.2
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.2" data-path="4.2.html">
            
                <a href="4.2.html">
            
                    
                    1.6.1-1.12.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="4.3.html">
            
                <a href="4.3.html">
            
                    
                    1.13.2-1.14.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="5.html">
            
                <a href="5.html">
            
                    
                    5 Mixin
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="5.1.html">
            
                <a href="5.1.html">
            
                    
                    配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="5.2.html">
            
                <a href="5.2.html">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="5.3.html">
            
                <a href="5.3.html">
            
                    
                    注入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="5.4.html">
            
                <a href="5.4.html">
            
                    
                    修改
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="5.5.html">
            
                <a href="5.5.html">
            
                    
                    定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="5.6.html">
            
                <a href="5.6.html">
            
                    
                    融合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="5.7.html">
            
                <a href="5.7.html">
            
                    
                    扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="5.8.html">
            
                <a href="5.8.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" >
            
                <span>
            
                    
                    附录
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="附录A.html">
            
                <a href="附录A.html">
            
                    
                    附录A 相关工具下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="附录B.html">
            
                <a href="附录B.html">
            
                    
                    附录B 常见Java字节码指令表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="附录C.html">
            
                <a href="附录C.html">
            
                    
                    附录C 参考资料
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >1.6.1-1.12.2</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="161-1122-fml-coremod&#x5927;&#x4E8B;&#x8BB0;">1.6.1-1.12.2 FML CoreMod&#x5927;&#x4E8B;&#x8BB0;</h1>
<ul>
<li>1.6 &#x4FEE;&#x6539;&#x4E86;&#x6E38;&#x620F;&#x6587;&#x4EF6;&#x7684;&#x7ED3;&#x6784;&#xFF0C;&#x5355;&#x4E00;.minecraft&#x6587;&#x4EF6;&#x5939;&#x5185;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x6E38;&#x620F;&#x7248;&#x672C;</li>
<li>1.6 &#x5F15;&#x5165;<a href="https://github.com/Mojang/LegacyLauncher" target="_blank">LaunchWrapper</a><ul>
<li>FML&#x4E0D;&#x518D;&#x901A;&#x8FC7;&#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x6E38;&#x620F;&#x7684;&#x6838;&#x5FC3;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x5B89;&#x88C5;&#xFF0C;&#x6539;&#x4E3A;&#x5148;&#x52A0;&#x5165;libraries&#xFF0C;&#x518D;&#x901A;&#x8FC7;&#x4F20;&#x9012;&#x53C2;&#x6570;<code>--tweakClass</code>&#x4F7F;&#x7528;LaunchWrapper&#x52A0;&#x8F7D;FML&#x5E76;&#x5BF9;Minecraft&#x8FDB;&#x884C;binpatch</li>
<li>FML&#x5F00;&#x59CB;&#x901A;&#x8FC7;LaunchWrapper&#x63D0;&#x4F9B;&#x7684;<code>IClassNameTransformer</code>&#x8FDB;&#x884C;&#x8FD0;&#x884C;&#x65F6;&#x53CD;&#x6DF7;&#x6DC6;&#xFF0C;&#x5C06;&#x8FD0;&#x884C;&#x65F6;&#x7684;&#x6DF7;&#x6DC6;&#x65B9;&#x5F0F;&#x4ECE;notch&#x52A8;&#x6001;&#x7684;&#x53CD;&#x6DF7;&#x6DC6;&#x6210;&#x4E86;srg</li>
<li>CoreMod&#x4E0D;&#x518D;&#x901A;&#x8FC7;FML&#x63D0;&#x4F9B;&#x7684;<code>RelaunchClassLoader</code>&#x5BF9;class&#x8FDB;&#x884C;&#x52A8;&#x6001;&#x4FEE;&#x6539;&#xFF0C;&#x6362;&#x7528;LaunchWrapper&#x5BF9;&#x5E94;&#x7684;<code>LaunchClassLoader</code></li>
<li>&#x53D6;&#x6D88;&#x4E86;<code>coremods</code>&#x6587;&#x4EF6;&#x5939;&#xFF0C;CoreMod&#x53EF;&#x4EE5;&#x88AB;&#x76F4;&#x63A5;&#x653E;&#x5165;<code>mods</code>&#x6587;&#x4EF6;&#x5939;&#xFF0C;CoreMod&#x4E5F;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x5305;&#x542B;&#x666E;&#x901A;Mod&#x4E86;</li>
</ul>
</li>
<li>1.7 &#x5F15;&#x5165;<a href="https://github.com/MinecraftForge/ForgeGradle" target="_blank">ForgeGradle</a>&#xFF0C;Forge&#x5F00;&#x53D1;&#x8131;&#x79BB;&#x4E86;MCP&#x5DE5;&#x5177;</li>
<li>1.7 MCP&#x5BF9;Minecraft&#x7684;&#x7C7B;&#x8FDB;&#x884C;&#x5206;&#x5305;&#xFF0C;&#x4E0D;&#x518D;&#x5B58;&#x653E;&#x4E8E;<code>net.minecraft.src</code></li>
<li>1.8 FML&#x53D8;&#x66F4;&#x4E86;&#x5305;&#x540D;&#xFF0C;&#x4ECE;<code>cpw.mods.fml</code>&#x6539;&#x6210;&#x4E86;<code>net.minecraftforge.fml</code></li>
</ul>
<h1 id="&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;">&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;</h1>
<p>&#xFF08;&#x5BF9;&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;&#x4E0D;&#x611F;&#x5174;&#x8DA3;&#x7684;&#x8BDD;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8DF3;&#x8FC7;&#x8FD9;&#x4E00;&#x90E8;&#x5206;&#xFF0C;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#x6765;&#x81EA;1.12.2FML&#xFF09;</p>
<p>Forge&#x5B98;&#x65B9;&#x6CA1;&#x6709;&#x7ED9;&#x51FA;CoreMod&#x7684;&#x6559;&#x7A0B;&#x4EE5;&#x53CA;&#x6587;&#x6863;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x63A2;&#x7D22;FML&#x5982;&#x4F55;&#x52A0;&#x8F7D;CoreMod&#x6765;&#x5F97;&#x51FA;&#x5236;&#x4F5C;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x5728;<a href="https://github.com/MinecraftForge/MinecraftForge/blob/1.12.x/src/main/java/net/minecraftforge/fml/relauncher/CoreModManager.java" target="_blank">CoreModManager</a>&#x4E2D;&#xFF0C;FML&#x7531;&#x4EE5;&#x4E0B;&#x65B9;&#x5F0F;&#x52A0;&#x8F7D;CoreMod&#xFF1A;</p>
<ul>
<li><code>discoverCoreMods</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x83B7;&#x53D6;Mod&#x6587;&#x4EF6;&#x5217;&#x8868;&#xFF0C;&#x904D;&#x5386;&#x6BCF;&#x4E2A;Mod&#x6587;&#x4EF6;<pre><code class="lang-java">List&lt;File&gt; file_canidates = LibraryManager.gatherLegacyCanidates(mcDir);
...
<span class="hljs-keyword">for</span> (File coreMod : file_canidates)
</code></pre>
</li>
<li><p>&#x8BFB;&#x53D6;Mod&#x6587;&#x4EF6;jar&#x4E2D;&#x7684;Manifest</p>
<pre><code class="lang-java">jar = <span class="hljs-keyword">new</span> JarFile(coreMod);
mfAttributes = jar.getManifest() == <span class="hljs-keyword">null</span> ? <span class="hljs-keyword">null</span> : jar.getManifest().getMainAttributes();
</code></pre>
</li>
<li><p>&#x901A;&#x8FC7;Manifest&#x4E2D;&#x7684;<code>FMLCorePlugin</code>&#x5C5E;&#x6027;&#x5B58;&#x5728;&#x4E0E;&#x5426;&#x6765;&#x5224;&#x65AD;&#x662F;&#x5426;&#x4E3A;CoreMod&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x662F;&#x5219;&#x68C0;&#x6D4B;&#x4E0B;&#x4E00;&#x4E2A;Mod&#x6587;&#x4EF6;</p>
<pre><code class="lang-java">fmlCorePlugin = mfAttributes.getValue(<span class="hljs-string">&quot;FMLCorePlugin&quot;</span>);
<span class="hljs-keyword">if</span> (fmlCorePlugin == <span class="hljs-keyword">null</span>)
{
  <span class="hljs-comment">// Not a coremod</span>
  FMLLog.log.debug(<span class="hljs-string">&quot;Not found coremod data in {}&quot;</span>, coreMod.getName());
  <span class="hljs-keyword">continue</span>;
}
</code></pre>
</li>
<li><p>&#x5C06;CoreMod&#x52A0;&#x5165;ClassPath&#xFF0C;&#x5E76;&#x8FDB;&#x884C;&#x52A0;&#x8F7D;</p>
<pre><code class="lang-java">classLoader.addURL(coreMod.toURI().toURL());
...
loadCoreMod(classLoader, fmlCorePlugin, coreMod);
</code></pre>
</li>
<li><p><code>loadCoreMod</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x53D6;&#x5F97;<code>IFMLLoadingPlugin</code>&#x5B9E;&#x4F8B;</p>
<pre><code class="lang-java">Class&lt;?&gt; coreModClazz = Class.forName(coreModClass, <span class="hljs-keyword">true</span>, classLoader);
...
IFMLLoadingPlugin plugin = (IFMLLoadingPlugin) coreModClazz.newInstance();
</code></pre>
</li>
<li><p>&#x5C06;<code>IFMLLoadingPlugin</code>&#x88C5;&#x9970;&#x4E3A;<code>FMLPluginWrapper</code>&#xFF0C;&#x52A0;&#x5165;&#x5217;&#x8868;</p>
<pre><code class="lang-java">FMLPluginWrapper wrap = <span class="hljs-keyword">new</span> FMLPluginWrapper(coreModName, plugin, location, sortIndex, dependencies);
loadPlugins.add(wrap);
</code></pre>
</li>
<li><p><code>injectCoreModTweaks</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;<code>FMLPluginWrapper</code>&#x4F5C;&#x4E3A;<code>ITweaker</code>&#x7684;&#x5B50;&#x7C7B;&#x76F4;&#x63A5;&#x52A0;&#x5165;LaunchWrapper&#x7684;Tweaks&#x5217;&#x8868;&#x4E2D;</p>
<pre><code class="lang-java">List&lt;ITweaker&gt; tweakers = (List&lt;ITweaker&gt;) Launch.blackboard.get(<span class="hljs-string">&quot;Tweaks&quot;</span>);
<span class="hljs-comment">// Add the sorting tweaker first- it&apos;ll appear twice in the list</span>
tweakers.add(<span class="hljs-number">0</span>, fmlInjectionAndSortingTweaker);
<span class="hljs-keyword">for</span> (FMLPluginWrapper wrapper : loadPlugins)
{
  tweakers.add(wrapper);
}
</code></pre>
</li>
</ul>
<p>&#x5728;LaunchWrapper&#x4E2D;&#x7684;<code>ITweaker</code>&#x8C03;&#x7528;&#x884C;&#x4E3A;&#x4E0E;<a href="3.3.html">&#x539F;&#x7248; CoreMod/LaunchWrapper</a>&#x4E00;&#x81F4;&#xFF0C;&#x4F1A;&#x4F9D;&#x636E;&#x987A;&#x5E8F;&#x9010;&#x4E2A;&#x8C03;&#x7528;<code>ITweaker</code>&#x3002;</p>
<p><code>FMLPluginWrapper</code>&#x4F1A;&#x88AB;LaunchWrapper&#x8C03;&#x7528;&#xFF1A;</p>
<ul>
<li><code>injectIntoClassLoader</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x9996;&#x5148;&#x8C03;&#x7528;<code>getASMTransformerClass</code>&#x83B7;&#x53D6;<code>IClassTransformer</code>&#x5BF9;&#x5E94;&#x7684;class&#x540D;&#x79F0;&#xFF0C;&#x4F7F;&#x7528;<code>TransformerWrapper</code>&#x8FDB;&#x884C;&#x88C5;&#x9970;&#x5E76;&#x5411;LaunchWrapper&#x6CE8;&#x518C;<pre><code class="lang-java"><span class="hljs-keyword">for</span> (String transformer : coreModInstance.getASMTransformerClass())
{
  classLoader.registerTransformer(ASMTransformerWrapper.getTransformerWrapper(classLoader, transformer, name));
}
</code></pre>
</li>
</ul>
<p>LaunchWrapper&#x4F1A;&#x5728;&#x6BCF;&#x4E2A;&#x7C7B;&#x88AB;&#x52A0;&#x8F7D;&#x8FDB;ClassLoader&#x4E4B;&#x524D;&#x8C03;&#x7528;<code>IClassTransformer</code>&#x7684;<code>transform</code>&#x65B9;&#x6CD5;&#xFF0C;&#x901A;&#x8FC7;&#x8FD9;&#x4E00;&#x65B9;&#x6CD5;&#xFF0C;&#x4FBF;&#x53EF;&#x8FD0;&#x884C;&#x65F6;&#x52A8;&#x6001;&#x4FEE;&#x6539;&#x5176;&#x4ED6;class&#x3002;</p>
<h1 id="&#x5236;&#x4F5C;&#x65B9;&#x6CD5;">&#x5236;&#x4F5C;&#x65B9;&#x6CD5;</h1>
<p>(&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#x9002;&#x7528;&#x4E8E;1.8-1.12.2&#xFF0C;1.6.2-1.7.10&#x9700;&#x8981;&#x53D8;&#x66F4;FML&#x5305;&#x540D;&#xFF0C;1.6.2-1.6.4&#x9700;&#x8981;&#x53D8;&#x66F4;Minecraft&#x5305;&#x540D;)</p>
<p>&#x901A;&#x8FC7;&#x4E0A;&#x6587;&#x5BF9;FML CoreMod&#x52A0;&#x8F7D;&#x65B9;&#x5F0F;&#x7684;&#x5206;&#x6790;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5F97;&#x5230;&#x4E09;&#x4E2A;&#x5173;&#x952E;&#x5185;&#x5BB9;&#x2014;&#x2014;Manifest&#x3001;<code>IFMLLoadingPlugin</code>&#x4E0E;<code>IClassTransformer</code>&#xFF0C;&#x4EE5;&#x4E0B;&#x9010;&#x4E2A;&#x4ECB;&#x7ECD;&#x3002; </p>
<p>&#x5982;&#x679C;&#x8BFB;&#x8005;&#x9605;&#x8BFB;&#x8FC7;<a href="4.1.html">FML CoreMod/1.3.2-1.5.2</a>&#x7684;&#x76F8;&#x5173;&#x5185;&#x5BB9;&#xFF0C;&#x4F1A;&#x53D1;&#x73B0;&#x5236;&#x4F5C;&#x65B9;&#x6CD5;&#x5927;&#x540C;&#x5C0F;&#x5F02;&#xFF0C;&#x65E0;&#x975E;&#x662F;&#x4F7F;&#x7528;LaunchWrapper&#x76F8;&#x5173;&#x7684;&#x7C7B;&#x8FDB;&#x884C;&#x5BF9;&#x5E94;&#x3002;</p>
<h2 id="manifest">Manifest</h2>
<p>Manifest&#x6709;&#x6E05;&#x5355;&#x7684;&#x610F;&#x601D;&#xFF0C;&#x5728;&#x8FD9;&#x91CC;&#x6307;&#x7684;&#x662F;jar&#x4E2D;&#x7684;<code>META-INF/MANIFEST.MF</code>&#x6587;&#x4EF6;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4FEE;&#x6539;<code>build.gradle</code>&#x81EA;&#x52A8;&#x5728;&#x6253;&#x5305;&#x65F6;&#x52A0;&#x5165;&#xFF1A;</p>
<pre><code class="lang-gradle">jar {
    manifest {
        attributes([
                <span class="hljs-string">&quot;FMLCorePlugin&quot;</span>: <span class="hljs-string">&quot;com.example.ExamplePlugin&quot;</span>,
                <span class="hljs-string">&quot;FMLCorePluginContainsFMLMod&quot;</span>: <span class="hljs-keyword">true</span>
        ])
    }
}
</code></pre>
<p>&#x5176;&#x4E2D;&#xFF1A;</p>
<ul>
<li><code>FMLCorePlugin</code>&#x5C5E;&#x6027;&#x662F;<code>IFMLLoadingPlugin</code>&#x5B9E;&#x73B0;&#x7C7B;&#x7684;&#x5B8C;&#x6574;&#x7C7B;&#x540D;</li>
<li><code>FMLCorePluginContainsFMLMod</code>&#x5C5E;&#x6027;&#x6807;&#x8BB0;CoreMod&#x7684;jar&#x4E2D;&#x662F;&#x5426;&#x8FD8;&#x542B;&#x6709;&#x666E;&#x901A;&#x7684;Mod&#xFF0C;&#x5982;&#x679C;&#x4E3A;false&#xFF0C;FML&#x4E0D;&#x4F1A;&#x5C1D;&#x8BD5;&#x5BFB;&#x627E;<code>@Mod</code>&#x6CE8;&#x89E3;&#x5E76;&#x52A0;&#x8F7D;&#x666E;&#x901A;Mod</li>
</ul>
<p>&#x8BFB;&#x8005;&#x53EF;&#x80FD;&#x4F1A;&#x6CE8;&#x610F;&#x5230;&#xFF0C;<code>jar</code>&#x662F;&#x4F1A;&#x5728;<code>build</code>&#x7B49;task&#x6253;&#x5305;&#x65F6;&#x624D;&#x4F1A;&#x88AB;&#x6267;&#x884C;&#xFF0C;&#x5728;<code>runClient</code>&#x4E4B;&#x7C7B;&#x7684;&#x6D4B;&#x8BD5;&#x8FD0;&#x884C;&#x65F6;&#x5E76;&#x4E0D;&#x4F1A;&#x88AB;&#x8BFB;&#x53D6;&#x5230;&#xFF0C;&#x5982;&#x679C;&#x9700;&#x8981;&#x5728;&#x6D4B;&#x8BD5;&#x8FD0;&#x884C;&#x65F6;&#x4F7F;&#x7528;CoreMod&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x5728;<code>build.gradle</code>&#x4E2D;&#x52A0;&#x5165;jvm&#x53C2;&#x6570;&#x7684;&#x8BBE;&#x7F6E;&#xFF1A;</p>
<pre><code class="lang-gradle">minecraft {
    ...
    clientJvmArgs += <span class="hljs-string">&quot;-Dfml.coreMods.load=com.example.ExamplePlugin&quot;</span>
    serverJvmArgs += <span class="hljs-string">&quot;-Dfml.coreMods.load=com.example.ExamplePlugin&quot;</span>
}
</code></pre>
<h2 id="ifmlloadingplugin">IFMLLoadingPlugin</h2>
<p><code>IFMLLoadingPlugin</code>&#x662F;FML&#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>getASMTransformerClass</code>&#xFF0C;&#x8FD4;&#x56DE;<code>IClassTransformer</code>&#x7684;&#x5B8C;&#x6574;&#x7C7B;&#x540D;&#x6784;&#x6210;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x8FD9;&#x662F;CoreMod&#x7684;&#x5173;&#x952E;</li>
<li><code>getModContainerClass</code>&#xFF0C;&#x8FD4;&#x56DE;<code>ModContainer</code>&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#x7684;&#x5B8C;&#x6574;&#x7C7B;&#x540D;&#xFF0C;&#x53EF;&#x7A7A;</li>
<li><code>getSetupClass</code>&#xFF0C;&#x8FD4;&#x56DE;<code>IFMLCallhook</code>&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#x5B8C;&#x6574;&#x7C7B;&#x540D;&#xFF0C;&#x53EF;&#x7A7A;</li>
<li><code>injectData</code>&#xFF0C;&#x53EF;&#x4EE5;&#x83B7;&#x5F97;<code>mcLocation</code>&#x3001;<code>coremodList</code>&#x4E0E;<code>coremodLocation</code>&#xFF0C;&#x5206;&#x522B;&#x662F;Minecraft&#x6587;&#x4EF6;&#x5939;<code>File</code>&#x3001;CoreMod&#x5217;&#x8868;<code>List</code>&#x3001;&#x5F53;&#x524D;CoreMod&#x6587;&#x4EF6;<code>File</code>&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E0E;<code>IFMLCallhook</code>&#x4E2D;&#x7684;<code>injectData</code>&#x4E3B;&#x8981;&#x533A;&#x522B;&#x4E3A;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x662F;&#x5728;Minecraft&#x542F;&#x52A8;&#x540E;&#x8C03;&#x7528;&#x7684;&#xFF0C;&#x53EF;&#x4EE5;&#x64CD;&#x4F5C;Minecraft&#x7684;class</li>
<li><code>getAccessTransformerClass</code>&#xFF0C;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;<code>AccessTransformer</code>&#x5B9E;&#x73B0;&#x7C7B;&#x5B8C;&#x6574;&#x7C7B;&#x540D;&#xFF0C;&#x53EF;&#x7A7A;&#xFF0C;&#x4E00;&#x822C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;FML&#x63D0;&#x4F9B;&#x7684;&#x8BBF;&#x95EE;&#x7EA7;&#x8F6C;&#x6362;&#x5668;&#x529F;&#x80FD;&#xFF0C;&#x65E0;&#x9700;&#x81EA;&#x5B9A;&#x4E49;</li>
</ul>
<p>&#x540C;&#x65F6;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x6CE8;&#x89E3;&#x6765;&#x8FDB;&#x884C;&#x4FE1;&#x606F;&#x8865;&#x5145;&#xFF1A;</p>
<ul>
<li><code>TransformerExclusions</code>&#xFF0C;&#x6307;&#x5B9A;&#x4E0D;&#x88AB;CoreMod&#x4FEE;&#x6539;&#x7684;&#x5305;&#x540D;&#x524D;&#x7F00;&#x6570;&#x7EC4;&#xFF0C;&#x4F8B;&#x5982;&#x6307;&#x5B9A;&#x4E86;<code>com.example</code>&#x540E;&#xFF0C;<code>com.example.something.Example</code>&#x4E5F;&#x4E0D;&#x4F1A;&#x88AB;&#x4FEE;&#x6539;</li>
<li><code>MCVersion</code>&#xFF0C;&#x6307;&#x5B9A;CoreMod&#x9002;&#x7528;&#x7684;Minecraft&#x7248;&#x672C;</li>
<li><code>Name</code>&#xFF0C;&#x6307;&#x5B9A;CoreMod&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x6307;&#x5B9A;&#xFF0C;&#x4F1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x7C7B;&#x540D;&#x4F5C;&#x4E3A;&#x540D;&#x5B57;</li>
<li><code>DependsOn</code>&#xFF0C;&#x6307;&#x5B9A;&#x4F9D;&#x8D56;</li>
<li><code>SortingIndex</code>&#xFF0C;&#x6307;&#x5B9A;&#x88AB;&#x8C03;&#x7528;&#x7684;&#x987A;&#x5E8F;</li>
</ul>
<p>&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;<code>IFMLLoadingPlugin</code>&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> java.util.Map;

<span class="hljs-keyword">import</span> net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
<span class="hljs-keyword">import</span> net.minecraftforge.fml.relauncher.IFMLLoadingPlugin.Name;

<span class="hljs-meta">@Name</span>(<span class="hljs-string">&quot;ExampleCoreMod&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExamplePlugin</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">IFMLLoadingPlugin</span> </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-keyword">public</span> String[] getASMTransformerClass() {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> String[]{<span class="hljs-string">&quot;com.example.ClassTransformer&quot;</span>};
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getModContainerClass</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getSetupClass</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">injectData</span><span class="hljs-params">(Map&lt;String, Object&gt; data)</span> </span>{
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getAccessTransformerClass</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }

}
</code></pre>
<h2 id="iclasstransformer">IClassTransformer</h2>
<p><code>IClassTransformer</code>&#x662F;LaunchWrapper&#x63D0;&#x4F9B;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x5B57;&#x8282;&#x7801;&#x4FEE;&#x6539;&#x5668;&#xFF0C;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0B;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>transform</code>&#xFF0C;&#x63A5;&#x6536;<code>name</code>&#x3001;<code>transformedName</code>&#x4E0E;<code>basicClass</code>&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5206;&#x522B;&#x662F;&#x539F;&#x7C7B;&#x540D;&#x3001;mcp&#x65E0;&#x6DF7;&#x6DC6;&#x7C7B;&#x540D;&#x548C;class&#x6587;&#x4EF6;&#x7684;&#x4E8C;&#x8FDB;&#x5236;<code>byte</code>&#x6570;&#x7EC4;&#xFF0C;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x4FEE;&#x6539;&#x540E;&#x7684;class&#x6587;&#x4EF6;&#x7684;<code>byte</code>&#x6570;&#x7EC4;</li>
</ul>
<p>&#x9700;&#x8981;&#x7279;&#x522B;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF1A;</p>
<ul>
<li><code>name</code>&#x539F;&#x7C7B;&#x540D;&#x548C;<code>basicClass</code> class&#x6587;&#x4EF6;&#xFF0C;&#x5728;&#x6E38;&#x620F;&#x8FD0;&#x884C;&#x65F6;&#x4E3A;notch&#x6DF7;&#x6DC6;&#xFF0C;&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x6D4B;&#x8BD5;&#x65F6;&#x4E3A;mcp&#x6DF7;&#x6DC6;</li>
<li><code>basicClass</code>&#x53EF;&#x80FD;&#x5DF2;&#x88AB;&#x5176;&#x4ED6;CoreMod&#x751A;&#x81F3;Forge&#x672C;&#x8EAB;&#x4FEE;&#x6539;&#x8FC7;</li>
<li>&#x5207;&#x8BB0;&#x65E0;&#x8BBA;&#x5982;&#x4F55;&#x90FD;&#x8981;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6709;&#x6548;&#x7684;<code>byte</code>&#x6570;&#x7EC4;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x5BFC;&#x81F4;<code>ClassNotFoundException</code>&#x3001;<code>NoClassDefFoundError</code>&#x7B49;&#x5BFC;&#x81F4;&#x7684;&#x5D29;&#x6E83;</li>
</ul>
<p>&#x4E00;&#x4E2A;&#x6CA1;&#x6709;&#x5BF9;class&#x8FDB;&#x884C;&#x4EFB;&#x4F55;&#x4FEE;&#x6539;&#x7684;<code>IClassTransformer</code>&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.IClassTransformer;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ClassTransformer</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">IClassTransformer</span> </span>{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">byte</span>[] transform(String name, String transformedName, <span class="hljs-keyword">byte</span>[] basicClass) {
        <span class="hljs-keyword">return</span> basicClass;<span class="hljs-comment">//&#x7279;&#x522B;&#x6CE8;&#x610F;&#x9700;&#x8981;&#x8FD4;&#x56DE;basicClass</span>
    }
}
</code></pre>
<p>&#x4E00;&#x4E2A;&#x5BF9;<code>net.minecraft.client.gui.GuiPlayerTabOverlay</code>&#x7684;<code>func_175249_a</code>(srg) <code>renderPlayerlist</code>(mcp)&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x7684;&#x5B9E;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.IClassTransformer;

<span class="hljs-keyword">import</span> net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;

<span class="hljs-keyword">import</span> org.objectweb.asm.ClassReader;
<span class="hljs-keyword">import</span> org.objectweb.asm.ClassWriter;
<span class="hljs-keyword">import</span> org.objectweb.asm.tree.ClassNode;
<span class="hljs-keyword">import</span> org.objectweb.asm.tree.MethodNode;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ClassTransformer</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">IClassTransformer</span> </span>{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">byte</span>[] transform(String name, String transformedName, <span class="hljs-keyword">byte</span>[] basicClass) {
        <span class="hljs-keyword">if</span> (!<span class="hljs-string">&quot;net.minecraft.client.gui.GuiPlayerTabOverlay&quot;</span>.equals(transformedName))
            <span class="hljs-keyword">return</span> basicClass;

        <span class="hljs-comment">//&#x4F7F;&#x7528;ASM&#x8BFB;&#x5165;basicClass</span>
        ClassReader cr = <span class="hljs-keyword">new</span> ClassReader(basicClass);
        ClassNode cn = <span class="hljs-keyword">new</span> ClassNode();
        cr.accept(cn, <span class="hljs-number">0</span>);

        <span class="hljs-comment">//&#x904D;&#x5386;methods</span>
        <span class="hljs-keyword">for</span> (MethodNode mn : cn.methods) {
            <span class="hljs-comment">//&#x8C03;&#x7528;FML&#x63A5;&#x53E3;&#x83B7;&#x5F97;&#x65B9;&#x6CD5;&#x540D;&#xFF0C;&#x8FD0;&#x884C;&#x65F6;&#x83B7;&#x5F97;&#x7684;&#x662F;srg&#xFF0C;&#x6D4B;&#x8BD5;&#x65F6;&#x83B7;&#x5F97;&#x7684;&#x662F;mcp</span>
            String methodName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(name, mn.name, mn.desc);
            <span class="hljs-keyword">if</span>(!<span class="hljs-string">&quot;func_175249_a&quot;</span>.equals(methodName) &amp;&amp; !<span class="hljs-string">&quot;renderPlayerlist&quot;</span>.equals(methodName)) 
                <span class="hljs-keyword">continue</span>;

            <span class="hljs-comment">//<span class="hljs-doctag">TODO:</span> &#x5728;&#x8FD9;&#x91CC;&#x8FDB;&#x884C;ASM&#x64CD;&#x4F5C;</span>
        }

        <span class="hljs-comment">//&#x8FD4;&#x56DE;&#x4FEE;&#x6539;&#x540E;&#x7684;bytes</span>
        ClassWriter cw = <span class="hljs-keyword">new</span> ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
        cn.accept(cw);
        <span class="hljs-keyword">return</span> cw.toByteArray();
    }
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="4.1.html" class="navigation navigation-prev " aria-label="Previous page: 1.3.2-1.5.2">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4.3.html" class="navigation navigation-next " aria-label="Next page: 1.13.2-1.14.4">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.6.1-1.12.2","level":"1.7.2","depth":2,"next":{"title":"1.13.2-1.14.4","level":"1.7.3","depth":2,"path":"4.3.md","ref":"4.3.md","articles":[]},"previous":{"title":"1.3.2-1.5.2","level":"1.7.1","depth":2,"path":"4.1.md","ref":"4.1.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"4.2.md","mtime":"2019-04-13T14:34:58.125Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-09-08T04:47:05.818Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

